package xyz.zhouzhousag.server.common.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger配置
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket createAPI() {
        return new Docket(DocumentationType.OAS_30)
                // 用来创建该API阿德基本信息，展示在文档的页面中（自定义展示的信息）
                .apiInfo(apiInfo())
                // 设置哪些接口暴露给Swagger展示
                .select()
                //扫描所有有注解的api，这种方式更灵活
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //指定包中的swagger注解
                //.apis(RequestHandlerSelectors.basePackage("xyz.xxx.server.controller"))
                //扫描所有 .apis
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 文档基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .version("1.0")
                //设置标题
                .title("ZhouForum接口文档")
                //描述
                .description("ZhouForum接口文档")
                //作者信息
                .contact(new Contact("Yin.Liu8", null, "sag7370@163.com"))
                .build();
    }
}